<?php

class nahoWikiConfiguration
{
  
  public static function loadInterwiki()
  {
    try
    {
      // load "app/config/interwiki.yml" in "app_nahoWikiPlugin_interwiki"
      require_once(sfApplicationConfiguration::getActive()->getConfigCache()->checkConfig('config/interwiki.yml')); 
    }
    catch (sfConfigurationException $e)
    {
      // file not found : skip
    }
  }
  
  public static function listenToRoutingLoadConfigurationEvent(sfEvent $event)
  {
    $r = $event->getSubject();

    // Common routes
    $r->prependRoute('wiki_home',           new sfRoute('/wiki',                      array('module' => 'nahoWiki', 'action' => 'index')));
    $r->prependRoute('wiki_view',           new sfRoute('/wiki/view/:page',           array('module' => 'nahoWiki', 'action' => 'view')));
    $r->prependRoute('wiki_view_revision',  new sfRoute('/wiki/view/:page/:revision', array('module' => 'nahoWiki', 'action' => 'view')));
    $r->prependRoute('wiki_edit',           new sfRoute('/wiki/edit/:page',           array('module' => 'nahoWiki', 'action' => 'edit')));
    $r->prependRoute('wiki_edit_revision',  new sfRoute('/wiki/edit/:page/:revision', array('module' => 'nahoWiki', 'action' => 'edit')));
    $r->prependRoute('wiki_history',        new sfRoute('/wiki/history/:page',        array('module' => 'nahoWiki', 'action' => 'history')));
    $r->prependRoute('wiki_diff',           new sfRoute('/wiki/diff/*',               array('module' => 'nahoWiki', 'action' => 'diff')));
    $r->prependRoute('wiki_index',          new sfRoute('/wiki/index/*',              array('module' => 'nahoWiki', 'action' => 'browse')));
    
    // Advanced routes
    $r->prependRoute('wiki_diff_full',      new sfRoute('/wiki/diff.:mode/:page/:revision_old/:revision_new',     array('module' => 'nahoWiki', 'action' => 'diff', 'raw' => '0')));
    $r->prependRoute('wiki_diff_raw',       new sfRoute('/wiki/diff.:mode.txt/:page/:revision_old/:revision_new', array('module' => 'nahoWiki', 'action' => 'diff', 'raw' => '1')));
    
    // Lucene route
    $r->prependRoute('wiki_lucene',         new sfRoute('/wiki/view-result/:sf_highlight/:page', array('module' => 'nahoWiki', 'action' => 'view')));
  }
  
}
